<template>
  <div>
    <!-- 顶部栏 -->
    <div class="header">
      <van-image
        width="60"
        height="60"
        fit="cover"
        round
        :src="userinfo.photo"
      />

      <h2>
        {{ userinfo.name }}
        <br />
        <van-tag color="#fff" text-color="#009afb">{{
          userinfo.birthday
        }}</van-tag>
      </h2>
    </div>

    <!-- 操作连接 -->
    <van-row>
      <van-col span="8">
        <van-icon name="newspaper-o" color="#c1c6ff" />
        <span>我的作品</span>
      </van-col>
      <van-col span="8">
        <van-icon name="star-o" color="#ff1f5b" />
        <span>我的收藏</span>
      </van-col>
      <van-col span="8">
        <van-icon name="tosend" color="#ffaf42" />
        <span>阅读历史</span>
      </van-col>
    </van-row>

    <!-- cell列表 -->
    <van-cell
      title="编辑资料"
      icon="edit"
      is-link
      @click="$router.push('/edit')"
    />
    <van-cell
      title="小智同学"
      icon="chat-o"
      is-link
      @click="$router.push('/student')"
    />
    <van-cell title="系统设置" icon="setting-o" is-link />
    <van-cell title="退出登入" icon="warning-o" is-link @click="logout" />
  </div>
</template>

<script>
import { getUserInfo } from "./user.js";
import { removeToken } from "../../utils/token.js";
export default {
  name: "user",
  data() {
    return {
      userinfo: {},
    };
  },
  methods: {
    // 退出登入
    logout() {
      this.$dialog
        .confirm({
          title: "标题",
          message: "是否确定退出",
        })
        .then(() => {
          removeToken();
          this.$router.push("/login");
        });
    },
  },
  // 首次进入渲染信息
  created() {
    getUserInfo().then((ret) => {
      this.userinfo = ret.data.data;
      this.$store.commit("updateUserInfo", ret.data.data);
    });
  },
};
</script>

<style lang='less'>
// 顶部栏
.header {
  height: 100px;
  background-color: #009afb;
  // 伸缩盒子
  display: flex;
  // 垂直居中
  align-items: center;

  .van-image {
    padding: 0px 10px;
  }

  h2 {
    font-size: 18px;
    color: #fff;
    font-weight: normal;
  }
}

// 操作链接
.van-row {
  .van-col {
    margin: 10px 0px;
    text-align: center;
    span {
      display: block;
      font-size: 12px;
    }
  }
}
</style>